package classify

import (
	"fmt"
	classifyDto "news_for_deepseek_interface/dto/admin/classify"
	"news_for_deepseek_interface/model"
)

func All(types string) (response classifyDto.AllResponse, err error) {
	db := model.GetInstance().GetDB()

	var data []model.ClassifyModel
	if err = db.Model(&model.ClassifyModel{}).
		Where("type = ?", types).
		Find(&data).Error; err != nil {
		err = fmt.Errorf("数据查询失败%s", err.Error())
		return
	}

	for _, v := range data {
		response.List = append(response.List, classifyDto.AllClassify{
			Id:       v.Id,
			Title:    v.Title,
			ParentId: v.ParentId,
		})
	}

	return
}
